package cate.game.rank.vo;

import cate.game.rank.po.Rank;
import easy.java.dev.note.NoteClass;
import easy.java.dev.note.NoteField;

import java.util.ArrayList;
import java.util.List;

@NoteClass(value = "排行榜范围")
public class RankRange {

    @NoteField(value = "排行榜数据条数限制", detail = "如果传3，就返回前3条数据，如果<=0，则全部返回")
    public int limit;

    public RankRange(int limit){
        this.limit = limit;
    }

    public <T> List<T> getList(List<T> list) {
        List<T> result = new ArrayList<>();
        if (limit <= 0 || limit >= list.size()) {
            result.addAll(list);
            return result;
        }
        for (int i = 0; i < limit; i++) {
            result.add(list.get(i));
        }
        return result;
    }

    public <T> List<T> getRankList(List<T> list){
        List<T> result = new ArrayList<>();
        if (limit <= 0 || limit >= list.size()) {
            result.addAll(list);
            return result;
        }
        for (int i = 0; i < limit; i++) {
            result.add(list.get(i));
        }
        return result;
    }
}
